package Array.Simulation;

import java.util.Arrays;

public class 逆时针旋转矩阵 {
    //暴力法
    public static int[][] rotateMatrix1(int[][] mat, int n) {
        // write code here
        int[][] temp = new int[n][n];//新建temp对象，作为最终返回的对象
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                //原矩阵的第i行变为了旋转矩阵的第i列;
                //原矩阵的第j列变为了旋转矩阵的倒数第j行;
                temp[n-1-j][i] = mat[i][j];//直接交换
            }
        }
        return temp;
    }

    public static void main(String[] args) {
        int[][] mat = new int[4][4];
        mat[0] = new int[]{1,2,3,4};
        mat[1] = new int[]{5,6,7,8};
        mat[2] = new int[]{9,10,11,12};
        mat[3] = new int[]{13,14,15,16};
        mat = rotateMatrix1(mat, 4);
        for (int i = 0; i < mat.length; i++) {
            System.out.println(Arrays.toString(mat[i]));
        }

    }
}
